package com.zk.wx.controller;

import com.zk.wx.model.TokenCach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.ws.soap.Addressing;
import java.util.Random;

/**
 * Created by 15911 on 2017/10/15.
 */
@RestController
@RequestMapping("/hello")
public class HelloController {

    @Autowired
    TokenCach tokenCach;

    @GetMapping
    public String hello(){
        return "get hello";
    }

    @PostMapping
    public String post(){
        return "post hello";
    }


    @GetMapping("/cach")
    public String cach(){
        String accessToken = tokenCach.getAccessToken();
        System.out.println("accessToken="+accessToken);
        if (accessToken == null){
            tokenCach.setAccessToken(Math.random() + "");
        }
        return tokenCach.getAccessToken();
    }
}
